#include <vector>

using namespace std;

class Solution {
public:

    // 153. 寻找旋转排序数组中的最小值
    // https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/
    int findMin(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;
        int size = nums.size();
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] > nums[size - 1])
                left = mid + 1;
            else if (nums[mid] < nums[size - 1])
                right = mid;
        }
        return nums[left];
    }

    // 剑指 Offer 53 - II. 0～n-1中缺失的数字
    // https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/
    int missingNumber(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] == mid)
                left = mid + 1;
            else
                right = mid;
        }
        if (left == nums[nums.size() - 1])
            return left + 1;
        else
            return left;
    }
};

// DP34 【模板】前缀和
// https://www.nowcoder.com/share/jump/8579736501694854727497
#include <vector>
#include <iostream>

using namespace std;

int main()
{
    int n = 0, q = 0;
    cin >> n >> q;
    vector<int> nums(n + 1);
    for (int i = 1; i<=n; ++i)
        cin >> nums[i];

    // 预处理前缀和数组
    vector<long> dp(n + 1);
    for (int i = 0; i<=n; ++i) 
        dp[i] = dp[i-1] + nums[i];
    // 求和
    int l = 0, r = 0;
    while (q--)
    {
        cin >> l >> r;
        cout << dp[r] - dp[l-1] << endl;
    }

    return 0;
}

// DP35 【模板】二维前缀和
// https://www.nowcoder.com/share/jump/8579736501694869389955
#include <iostream>
#include <vector>
using namespace std;

int main() 
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<vector<int>> nums(n+1, vector<int>(m+1));
    for (int i = 1; i<=n; ++i)
    {
        for (int j = 1; j<=m; ++j)
        {
            cin >> nums[i][j];
        }
    }

    vector<vector<long long>> dp(n+1, vector<long long>(m+1));
    for (int i = 1; i<=n; ++i)
    {
        for (int j = 1; j<=m; ++j)
        {
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + nums[i][j];
        }
    }

    int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    while (q--)
    {
        cin >> x1 >> y1 >> x2 >> y2;
        cout << dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1] << endl;
    }

    return 0;
}